{% macro render_toc(items, max_depth, current_depth=1) %}
{% for item in items %}
<li>
  <a href="{{ item.permalink | safe }}">{{ item.title }}</a>
  {% if item.children and current_depth < max_depth %}
  <ul>
    {{ self::render_toc(items=item.children, max_depth=max_depth, current_depth=current_depth + 1) | safe }}
  </ul>
  {% endif %}
</li>
{% endfor %}
{% endmacro %}


{% macro render_parent_link(current_path) %}
{% if "/" in current_path %}
{% set last_char = current_path | split(pat="/") | last %}
{% if last_char == "" %}
{% set parent_dirs = current_path | split(pat="/") | slice(end=-2) %}
{% else %}
{% set parent_dirs = current_path | split(pat="/") | slice(end=-1) %}
{% endif %}
{% set parent_href = parent_dirs | join(sep="/") %}
<a
  class="nav__link"
  href="{{ parent_href }}"
  aria-label="Navigation to the parent path; aka 'Back up'."
>Parent</a>
{% endif %}
{% endmacro %}
